import { defineStore } from "pinia";
import routeConfig from "@/utils/route.config";

export const useRouteBread = defineStore("routebread", {
  persist: true, //开启数据持久化
  //数据持久化参数
  persist: [
    {
      key: "openClose",
      storage: localStorage,
      paths: ["openClose"],
    },
    {
      key: "routerNowId",
      storage: localStorage,
      paths: ["routeObj"],
    },
    {
      key: "routebreadArr",
      storage: localStorage,
      paths: ["routebreadArr"],
    },
    {
      key: "routerList",
      storage: localStorage,
      paths: ["routerList"],
    },
  ],
  state: () => {
    return {
      openClose: false, // 侧边栏展开还是收起
      routeObj: {
        [routeConfig.path]: routeConfig.storeDefaultPath,
        [routeConfig.name]: routeConfig.storeDefaultName,
      }, // 路由菜单当前选中的值
      routebreadArr: [
        {
          [routeConfig.path]: routeConfig.storeDefaultPath,
          [routeConfig.name]: routeConfig.storeDefaultName,
        },
      ], //路由面包屑数组
      routerList: [], // 后台请求回来的路由数组
    };
  },
  actions: {},
  getters: {},
});
